/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImprimirProductos.java
 *
 * Created on 25-may-2009, 12:21:45
 */

package tarifas;

import clientes.Cliente;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import emailSW.MailUtils;
import empresa.DatosEmpresa;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Query;
import productos.Producto;

/**
 *
 * @author rocio
 */
public class ImprimirProductos extends javax.swing.JFrame {
    private Document documento;
    private Boolean a;
    private Producto producto;
    private Cliente cliente;
    private Query q;
    /** Creates new form ImprimirProductos */
    public ImprimirProductos() throws DocumentException, Exception {
        initComponents();
        this.imprimir();
    }


    public void imprimir() throws DocumentException, Exception{
        documento=new Document();
        String tit="Tarifas.pdf";
        try{
            PdfWriter.getInstance (documento, new FileOutputStream (tit));
        }catch(Exception e){
        }
        Date d=new Date();
        int x= d.getYear()+1900;
        documento.open();
        a=documento.add(new Paragraph("                                                           Tarifa de precios "+x));
        documento.add(new Paragraph("---------------------------------------------------------------------------------------------------------------------\n"));
        Iterator it=productoList.iterator();
        while(it.hasNext()){
            producto=(Producto) it.next();
            documento.add(new Paragraph("          Concepto: "+producto.getConcepto()));
            documento.add(new Paragraph("                            Precio: "+producto.getPrecio()));
        }
        documento.close();
        try {
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + tit);
        } catch (IOException ex) {
            
        }
        
       

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lpdPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("lpdPU").createEntityManager();
        productoQuery = java.beans.Beans.isDesignTime() ? null : lpdPUEntityManager.createQuery("SELECT p FROM Producto p");
        productoList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : productoQuery.getResultList();
        clienteQuery = java.beans.Beans.isDesignTime() ? null : lpdPUEntityManager.createQuery("SELECT c FROM Cliente c");
        clienteList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : clienteQuery.getResultList();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new ImprimirProductos().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(ImprimirProductos.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.util.List<clientes.Cliente> clienteList;
    private javax.persistence.Query clienteQuery;
    private javax.persistence.EntityManager lpdPUEntityManager;
    private java.util.List<productos.Producto> productoList;
    private javax.persistence.Query productoQuery;
    // End of variables declaration//GEN-END:variables

}
